/* ===================================================================== Rebeca Ramagem — comportamento do site Sem dependências. Só o que a referência faz: menu mobile, cabeçalho ao rolar, barra de progresso, revelar ao rolar, carrossel de prioridades (setas + dots). ===================================================================== */ (function () { 'use strict'; var reduzMovimento = window.matchMedia('(prefers-reduced-motion: reduce)').matches; /* ---------- 1. Menu mobile ---------- */ var toggle = document.getElementById('menuToggle'); var menu = document.getElementById('menuMobile'); if (toggle && menu) { var fecharMenu = function () { menu.classList.remove('aberto'); menu.setAttribute('aria-hidden', 'true'); document.body.classList.remove('menu-aberto'); toggle.setAttribute('aria-expanded', 'false'); toggle.setAttribute('aria-label', 'Abrir menu'); }; toggle.addEventListener('click', function () { var abrir = !menu.classList.contains('aberto'); menu.classList.toggle('aberto', abrir); menu.setAttribute('aria-hidden', String(!abrir)); document.body.classList.toggle('menu-aberto', abrir); toggle.setAttribute('aria-expanded', String(abrir)); toggle.setAttribute('aria-label', abrir ? 'Fechar menu' : 'Abrir menu'); }); menu.querySelectorAll('a').forEach(function (link) { link.addEventListener('click', fecharMenu); }); document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && menu.classList.contains('aberto')) { fecharMenu(); toggle.focus(); } }); } /* ---------- 2. Cabeçalho ao rolar + 3. Barra de progresso ---------- */ var cabecalho = document.getElementById('cabecalho'); var progresso = document.getElementById('progressoScroll'); var pendente = false; var atualizarScroll = function () { var topo = window.scrollY || document.documentElement.scrollTop; var altura = document.documentElement.scrollHeight - window.innerHeight; var pct = altura > 0 ? (topo / altura) * 100 : 0; document.documentElement.style.setProperty('--scroll-progress', pct + '%'); if (progresso) progresso.style.width = pct + '%'; if (cabecalho) cabecalho.classList.toggle('rolado', topo > 22); pendente = false; }; var pedirAtualizacao = function () { if (pendente) return; pendente = true; window.requestAnimationFrame(atualizarScroll); }; atualizarScroll(); window.addEventListener('scroll', pedirAtualizacao, { passive: true }); window.addEventListener('resize', pedirAtualizacao, { passive: true }); /* ---------- 4. Revelar ao rolar ---------- */ var alvos = [].slice.call(document.querySelectorAll('.reveal')); alvos.forEach(function (el, i) { el.style.setProperty('--reveal-delay', Math.min((i % 5) * 55, 220) + 'ms'); }); if (reduzMovimento || !('IntersectionObserver' in window)) { alvos.forEach(function (el) { el.classList.add('visivel'); }); } else { var obs = new IntersectionObserver(function (entradas) { entradas.forEach(function (en) { if (en.isIntersecting) { en.target.classList.add('visivel'); obs.unobserve(en.target); } }); }, { threshold: 0.12, rootMargin: '0px 0px -6% 0px' }); alvos.forEach(function (el) { obs.observe(el); }); } /* ---------- 5. Carrossel de prioridades ---------- */ var trilha = document.getElementById('prioridadesTrilha'); var prev = document.getElementById('prioridadesPrev'); var next = document.getElementById('prioridadesNext'); var dotsBox = document.getElementById('prioridadesDots'); if (trilha) { var cards = [].slice.call(trilha.querySelectorAll('.prioridade-card')); var indiceAtual = function () { var centro = trilha.scrollLeft + trilha.clientWidth / 2; var maisPerto = 0; var menorDist = Infinity; cards.forEach(function (card, i) { var c = card.offsetLeft + card.offsetWidth / 2; var d = Math.abs(c - centro); if (d < menorDist) { menorDist = d; maisPerto = i; } }); return maisPerto; }; var irPara = function (i) { var alvo = Math.max(0, Math.min(cards.length - 1, i)); var card = cards[alvo]; if (!card) return; var left = card.offsetLeft - (trilha.clientWidth - card.clientWidth) / 2; trilha.scrollTo({ left: Math.max(0, left), behavior: reduzMovimento ? 'auto' : 'smooth' }); }; if (prev) prev.addEventListener('click', function () { irPara(indiceAtual() - 1); }); if (next) next.addEventListener('click', function () { irPara(indiceAtual() + 1); }); var dots = []; if (dotsBox) { cards.forEach(function (_, i) { var b = document.createElement('button'); b.type = 'button'; b.setAttribute('aria-label', 'Ir para a prioridade ' + (i + 1)); b.addEventListener('click', function () { irPara(i); }); dotsBox.appendChild(b); dots.push(b); }); } var sincronizarDots = function () { var at = indiceAtual(); dots.forEach(function (d, i) { d.classList.toggle('ativo', i === at); }); }; sincronizarDots(); trilha.addEventListener('scroll', function () { window.requestAnimationFrame(sincronizarDots); }, { passive: true }); } })();